<!--
 * @Author: 薛严 348352046@qq.com
 * @Date: 2023-05-04 17:54:20
 * @LastEditors: 薛严 348352046@qq.com
 * @LastEditTime: 2023-05-05 17:53:27
 * @FilePath: /gd-auth-demo-h5/src/components/HelloWorld.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->

<script setup>
import { ref } from "vue";
import wx from "weixin-sdk-js";
import { createAes } from "./crypto";
defineProps({
  msg: String,
});

const count = ref(0);
const result = ref("跳转认证");
//  获取参数
const getParams = () => {
  const newObj = new Object();
  let url = location.search;
  if (url.indexOf("?") !== -1) {
    url = url.substring(url.length, 1);
    const strs = url.split("&");
    strs.map((item, index) => {
      newObj[strs[index].split("=")[0]] = strs[index].split("=")[1] || "";
    });
  }
  return newObj;
};
// 解密
const decrypt = () => {
  const key = "ift@2023!xy20235"
  const cyrpto = createAes(key);
  // 默认测试数据
  const tempEntryData = {
   iftAuthCode:"wyoXju3qhkVXXTKSBygJQyFzP7e5QvH3KD%2FdFCQsNfOyP2E8YadRAcxIJqguQ5u%2B"
  }
  // 获取url中参数
  const data = getParams() || tempEntryData
  // 解密
  const decryptData = cyrpto.decrypt(decodeURIComponent(data.iftAuthCode));
  console.log("decryptData===>", decryptData);
  return decryptData;
};

// 处理结果
const handleResult = () => {
  const r = decrypt();
  console.log(r);
  if (r) result.value = "认证成功";
};
handleResult();

// 跳转认证
const navigateToAuth = () => {
  // title: 最多10个中文字
  const url = `/subs/auth-ca/pages/gd-auth/index?path=${encodeURIComponent(
    location.href
  )}&title=${encodeURIComponent("鎏嫣宫")}`;
  wx.miniProgram.redirectTo({
    url,
  });
};
</script>

<template>
  <h1>{{ msg }}</h1>

  <div class="card">
    <button type="button" @click="count++">count is {{ count }}</button>
  </div>
  <button @click="navigateToAuth">{{ result }}</button>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
</style>
